<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<title>${name_china}管理列表</title>
<%@include file="/common/head.jsp" %>

</head>
<body class="iframe-page">
<div class="page-title-wrapper">
    <div class="page-title">
        <div class="page-title-text">
            <span>${name_china}管理</span>
        </div>
        <div id="toolbar" style="float: right"></div>
    </div>
    <div class="page-title-border"></div>
</div>

<div class="search-field">
     <span class="field-cont">
        <span class="field-cont-title">订单编号</span>
        <input type="text" class="summer-input" id="orderNum"/>
    </span>
    
    <span class="field-btn-wrapper">
        <a id="search" class="btn btn-primary btn-icon wave distance-right"><i class="icon icon-search"></i></a>
        <a id="reset" class="btn btn-icon wave wave-dark"><i class="icon icon-refresh"></i></a>
    </span>
</div>

<div id="t-wrap">
    <table class="summer-datagrid" id="dataList">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	    <thead>
		    <tr>
		    	<th>京东的订单号码</th>
		        <th>订单创建时间</th>
		        <th>订单实际计算佣金使用金额</th>
				<th>是否结算</th>
		        <th>推广位ID</th>
		        <th>推广位名称</th>
		        <th>云店主ID</th>
		        <th>用户ID</th>
		        <th>订单状态</th>
		        <th>操作</th>
		    </tr>
	    </thead>
    </table>
</div>

<script>
	//请求url
	var CONST_URL = {
		LIST: basePath + '${common_url}list',
	   	INIT_ADD: basePath + "${common_url}initAdd",
	   	INIT_EDIT: basePath + "${common_url}initEdit",
	   	INIT_VIEW: basePath + "${common_url}initView",
	   	DEL: basePath + "${common_url}del",
	   	NOW_SYSN: "http://develop.jhjvip.cn:8080/mall/mobile/userspay/cal/profit"
	};
	
    var  permission = CommonUtil.getPermission('${name_english}');
    
    $(function () {
    	
    	
        // 新建toobar
		$.funcbar({
			id: 'toolbar',
			type: 'toolbar',
			data: permission,
			permit: ['${name_english}:initAdd']
		});
        
        // 查询按钮
        $('#search').on('click', reloadTable);
        
        //重置按钮
        $('#reset').on('click', function () {
        	//重置文本框的值
        	$('#orderNum').val("");
        	reloadTable();
        });
        
        //新建
        $('#toolbar').on('click', 'a[data-permit="${name_english}:initAdd"]', function() {
        	window.location.href = CONST_URL.INIT_ADD; 	  	
		});
        
        
       createTable();
        
        //查看
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:initView"]', function() {
        	var $this = $(this),
        	    id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
        	window.location.href = CONST_URL.INIT_VIEW +"?id=" + id;
        });
       
        //编辑
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:initEdit"]', function() {
            var $this = $(this),
                id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
            window.location.href = CONST_URL.INIT_EDIT + '?id=' + id;
        });	
        
        //删除
		$('#t-wrap').on('click', 'a[data-permit="${name_english}:del"]', function() {
			var $this = $(this),
			    id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
			$.sdialog({
				type: 'confirm',
				msg: '您确定要删除选中的记录吗?',
				onConfirm: function(result) {
				    if (result) {
				    	$.sajax({
			                url : CONST_URL.DEL + "?id=" + id,
			                onLoadSuccess : function() {
			                	 $.stip({
                	                type:'ok',//显示类型 有info、 ok、 danger
                	                text: '删除成功！'    
			                	});
			                	reloadTable();  
			                }
			            });
				    		
				    }	
				}
			});
		});
        
    });
    
	function nowSysn(orderId,userId,commission,orderNo,orderStatus){
		
    	if("U0" == orderStatus){
    		$.ajax({
       			url: CONST_URL.NOW_SYSN,
       			type: 'POST',
       			dataType: 'json',
       			data:{
       				"orderId": orderId,
       				"userId": userId,
       				"commission": commission,
       				"orderNo": orderNo
       			},
       			success:function(data){
       				console.log(data); 
            	 }
       		});
    	}else{
    		 $.stip({
	                type:'danger',//显示类型 有info、 ok、 danger
	                text: '该订单不能立即同步！',
	                onBeforeHide: function () {
	               }
         	});
    	}
    }
    
    // 重新加载表格
	function reloadTable() {
		$('#dataList').datagrid('reload',{
            ajax: {
            	param: {
            		"orderNum": trimSpace($('#orderNum').val())
                	//"startTime": trimSpace($('#startTime').val()),
                	//"stopTime": trimSpace($('#stopTime').val())
            	}
            }
        });
	}
    
    //创建表格
    function createTable() {
    	$('#dataList').datagrid({
    		ajax: {
    			url: CONST_URL.LIST,
    			param: {
    				"orderNum": trimSpace($('#orderNum').val())
                	//"startTime": trimSpace($('#startTime').val()),
                	//"stopTime": trimSpace($('#stopTime').val())
            	}
    		},
    		//$('#dg').datagrid('loadData', data); 
    		columns: [
    		     {
    		    	 field: 'id',
    		    	 hidden: true
    		     },
    		     {
    		    	 field: 'orderNum'/* ,
    		    	 render: function (rowData) {
    		    		 return '<a href="javascript:;" data-permit="${name_english}:initView" class="link">'+ rowData.orderNum +'</a>';
    		    	 } */
    		     },
    		     {
    		    	 field: 'orderDate'
    		     },
    		     {
    		    	 field:'orderTotalMoney'
    		     },
    		     {
    		    	 field:'isJiesuan'
    		     },
    		     {
    		    	 field:'tgwId'
    		     },
    		     {
    		    	 field:'tgwName'
    		     },
    		     {
    		    	 field:'yunUserId'
    		     },
    		     {
    		    	 field: 'userId'
    		     },{
    		    	 field: 'orderStatus',
    		    	 render: function (rowData) {
    		    		 if("L1" == rowData.orderStatus){
    		    			 return  "累计计算成功";
    		    		 }else if("L0" == rowData.orderStatus){
    		    			 return  "累计计算失败";
    		    		 }else if("Y1" == rowData.orderStatus){
    		    			 return  "预计计算成功";
    		    		 }else if("Y2" == rowData.orderStatus){
    		    			 return  "预计已计算";
    		    		 }else if("Y0" == rowData.orderStatus){
    		    			 return  "预计计算失败";
    		    		 }else if("U0" == rowData.orderStatus){
    		    			 return  "用户异常";
    		    		 }else if("D0" == rowData.orderStatus){
    		    			 return  "订单未结算";
    		    		 }
    		    	 }
    		     },{
    		    	 render: function (rowData) {
    		    		 var id = rowData.id;
    		    		 var userId = rowData.userId;
    		    		 var commission = rowData.commisions;
    		    		 var orderNo =	rowData.orderNum;
    		    		 var orderStatus = rowData.orderStatus;
    		    		return  "<button onclick = nowSysn('" + id + "','" + userId + "','" + commission + "','" + orderNo+ "','" + orderStatus+ "')>立即同步</button>";
    		    	 }
		         } 
    	    ]
    	});
    }

   
   
</script>
</body>
</html>